home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxutil / tspak17 / setdac.asm < prev    next >
Encoding:
Assembly Source File  |  1994-07-26  |  4.3 KB  |  246 lines

  1. ; SETDAC.ASM
  2. ;
  3. ; Version 1.3 - July 25, 1994.  Modified to improve detection of the DAC,
  4. ; to make the base I/O port of the DAC a variable, and to display the port
  5. ; address to the user.
  6. ;
  7. ; This program sets up the DAC to take direct writes.  If this program is
  8. ; run before another program that writes 8-bit unsigned samples to a DAC
  9. ; at the port displayed by Setdac, the program should produce better sound 
  10. ; than is available with the PC speaker.
  11. ;
  12.  
  13.     JMP    START
  14.  
  15. ;
  16. ; Data.
  17. ;
  18. SOUNDHALTED    DB    0
  19. INT15DEFAULT    DD    0
  20. PORTBASE    DW    0        ; base I/O port of DAC
  21. NODACMSG    DB    "Tandy DAC not detected.",0Dh,0Ah,"$"
  22. PORTMSG1    DB    "Tandy DAC at port $"
  23. PORTMSG2    DB    "h",0Dh,0Ah,"$"
  24.  
  25. ;
  26. ; Replacement Int 15h handler, for BIOS callout.
  27. ;
  28. INT15HDLR:
  29.     CMP    AX,91FBh
  30.     JE    >L0
  31.     JMP    DWORD PTR CS:INT15DEFAULT
  32. L0:    MOV    CS:SOUNDHALTED,1
  33.     IRET
  34.  
  35. ;
  36. ; Routine to check whether there is BIOS support for Tandy sound functions.  
  37. ; Sets carry if no Tandy DAC found; otherwise, carry is cleared and the base
  38. ; I/O port of the DAC is returned in AX.  (Modified, 7/13/1994.)
  39. ;
  40. CHKDAC:
  41.     PUSH    CX
  42.     PUSH    DX
  43.     ;
  44.     ; Check for PCMCIA Socket Services.
  45.     ;
  46.     MOV    AX,8003h
  47.     XOR    CX,CX
  48.     INT    1Ah
  49.     CMP    CX,5353h
  50.     JE    CHKDAC_NODAC
  51.     ;
  52.     ; Check for Tandy DAC.
  53.     ;
  54.     MOV    AX,8100h
  55.     INT    1Ah
  56.     CMP    AX,8100h
  57.     JE    CHKDAC_NODAC
  58.     ;
  59.     ; DAC found.  Base port returned in AX.  Verify the presence of a
  60.     ; read/write port at (base+2).
  61.     ;
  62.     MOV    DX,AX        ; DX addresses (base+2)
  63.     INC    DX
  64.     INC    DX
  65.     MOV    CL,40h        ; set bit 6 of CL (assume port present)
  66.     CLI            ; disable interrupts
  67.     IN    AL,DX        ; save value from port in CH
  68.     JMP    $+2
  69.     MOV    CH,AL
  70.     MOV    AL,0FFh        ; set all bits of port
  71.     OUT    DX,AL
  72.     JMP    $+2
  73.     MOV    AL,0        ; clear all bits
  74.     OUT    DX,AL
  75.     JMP    $+2
  76.     IN    AL,DX        ; read back and test
  77.     JMP    $+2
  78.     OR    AL,AL
  79.     LAHF
  80.     AND    CL,AH        ; bit 6 of CL still set if successful
  81.     MOV    AL,0FFh        ; set all bits
  82.     OUT    DX,AL
  83.     JMP    $+2
  84.     IN    AL,DX        ; read back and test
  85.     JMP    $+2
  86.     NOT    AL
  87.     OR    AL,AL
  88.     LAHF
  89.     AND    CL,AH        ; bit 6 of CL still set if successful
  90.     MOV    AL,CH        ; write back saved value
  91.     OUT    DX,AL
  92.     JMP    $+2
  93.     STI            ; enable interrupts
  94.     TEST    CL,40h        ; if bit 6 of CL still set, port found
  95.     JZ    CHKDAC_NODAC
  96.     ;
  97.     ; Read/write port found.  Return port base in AX.
  98.     ;
  99.     MOV    AX,DX
  100.     DEC    AX        ; decrement twice to get base port back
  101.     DEC    AX
  102.     CLC
  103.     JMP    CHKDAC_END
  104. CHKDAC_NODAC:
  105.     STC
  106. CHKDAC_END:
  107.     POP    DX
  108.     POP    CX
  109.     RET
  110.  
  111. ;
  112. ; Routine to display a hex digit.  The digit is in AL.
  113. ;
  114. HEXDIGIT:
  115.     PUSH    AX
  116.     PUSH    DX
  117.     CMP    AL,9
  118.     JA    HEXDIGIT_LETTER
  119.     ADD    AL,'0'
  120.     JMP    HEXDIGIT_DISPLAY
  121. HEXDIGIT_LETTER:
  122.     ADD    AL,'A'-10
  123. HEXDIGIT_DISPLAY:
  124.     MOV    DL,AL
  125.     MOV    AH,2
  126.     INT    21h
  127.     POP    DX
  128.     POP    AX
  129.     RET
  130.  
  131. ;
  132. ; Routine to display a word in hex.  The word is passed in AX.
  133. ;
  134. HEXWORD:
  135.     PUSH    AX
  136.     PUSH    BX
  137.     PUSH    CX
  138.     PUSH    DX
  139.     MOV    DX,AX
  140.     MOV    BL,12
  141.     MOV    CX,4
  142. HEXWORD_LOOP:
  143.     PUSH    CX
  144.     MOV    AX,DX
  145.     MOV    CL,BL
  146.     SHR    AX,CL
  147.     AND    AL,0Fh
  148.     CALL    HEXDIGIT
  149.     SUB    BL,4
  150.     POP    CX
  151.     LOOP    HEXWORD_LOOP
  152.     POP    DX
  153.     POP    CX
  154.     POP    BX
  155.     POP    AX
  156.     RET
  157.  
  158. ;
  159. ; Main program.
  160. ;
  161. START:
  162.     ;
  163.     ; Check whether the needed sound circuitry is present; display error
  164.     ; message and halt if not.
  165.     ;
  166.     CALL    CHKDAC
  167.     JNC    DACFOUND
  168.     MOV    DX,OFFSET NODACMSG
  169.     MOV    AH,9
  170.     INT    21h
  171.     JMP    TERMINATE
  172.     ;
  173.     ; Save the I/O port returned.
  174.     ;
  175. DACFOUND:
  176.     MOV    PORTBASE,AX
  177.     ;
  178.     ; Display the output port (base+1) to the user.
  179.     ;
  180.     MOV    DX,OFFSET PORTMSG1
  181.     MOV    AH,9
  182.     INT    21h
  183.     MOV    AX,PORTBASE
  184.     INC    AX
  185.     CALL    HEXWORD
  186.     MOV    DX,OFFSET PORTMSG2
  187.     MOV    AH,9
  188.     INT    21h
  189.     ;
  190.     ; Use the replacement Int 15h handler now.
  191.     ;
  192.     MOV    AX,3515h
  193.     INT    21h
  194.     MOV    WORD PTR INT15DEFAULT,BX
  195.     MOV    WORD PTR INT15DEFAULT+2,ES
  196.     MOV    DX,OFFSET INT15HDLR
  197.     MOV    AX,2515h
  198.     INT    21h
  199.     ;
  200.     ; Initialize/finalize the sound chip.
  201.     ;
  202.     MOV    SOUNDHALTED,0
  203. L0:    MOV    AH,84h
  204.     INT    1Ah
  205. L1:    MOV    AH,81h
  206.     INT    1Ah
  207.     JC    L1
  208.     CMP    SOUNDHALTED,0
  209.     JE    L0
  210.     ;
  211.     ; Restore Int 15h vector to default.
  212.     ;
  213.     PUSH    DS
  214.     MOV    AX,2515h
  215.     MOV    DX,WORD PTR INT15DEFAULT
  216.     MOV    DS,WORD PTR INT15DEFAULT+2
  217.     INT    21h
  218.     POP    DS
  219.     ;
  220.     ; Set DAC for direct write (byte-by-byte, without DMA).
  221.     ;
  222.     MOV    DX,PORTBASE
  223.     CLI
  224.     IN    AL,DX        ; set base port (DAC Control Register)
  225.     JMP    $+2
  226.     AND    AL,0E3h
  227.     OR    AL,3
  228.     OUT    DX,AL
  229.     JMP    $+2
  230.     INC    DX        ; set volume at (base+2), (base+3)
  231.     INC    DX
  232.     MOV    AL,0
  233.     OUT    DX,AL
  234.     JMP    $+2
  235.     INC    DX
  236.     MOV    AL,0E0h
  237.     OUT    DX,AL
  238.     JMP    $+2
  239.     STI
  240.     ;
  241.     ; Terminate.
  242.     ;
  243. TERMINATE:
  244.     MOV    AX,4C00h
  245.     INT    21h
  246.